/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package com.yutel.gui;

import com.yutel.main.WSClientMIDlet;
import com.yutel.util.LangUtil;
import javax.microedition.lcdui.Command;
import javax.microedition.lcdui.CommandListener;
import javax.microedition.lcdui.Displayable;
import javax.microedition.lcdui.Form;
import javax.microedition.lcdui.List;

/**
 *
 * @author yuanyajun
 */
public class OptionForm extends Form implements CommandListener {

    private List list;
    private Command backCom;
    private Command okCom;

    public OptionForm() {
        super(LangUtil.getInstance().getMessage(LangUtil.tit_preferences));
        try {
            exeute();
        } catch (Exception e) {
            e.printStackTrace();
        }
    }

    private void exeute() throws Exception {
        // add the Exit command
        backCom = new Command(LangUtil.getInstance().getMessage(LangUtil.but_back), Command.BACK, 1);
        okCom = new Command(LangUtil.getInstance().getMessage(LangUtil.but_submit), Command.OK, 1);
        // Set up this Displayable to listen to command events
        String[] langs = {
            LangUtil.getInstance().getMessage(LangUtil.lang_en),
            LangUtil.getInstance().getMessage(LangUtil.lang_zh_cn)
        };
        list = new List(LangUtil.getInstance().getMessage("tag_lang"), List.IMPLICIT, langs, null);
        list.addCommand(backCom);
        list.addCommand(okCom);
        list.setCommandListener(this);
    }

    public void commandAction(Command command, Displayable displayable) {
        if (command == backCom) {
            IndexForm index = new IndexForm();
            WSClientMIDlet.setDisplay(index);
        } else if (command == okCom) {
            switch (list.getSelectedIndex()) {
                case 0:
                    LangUtil.getInstance().setLang("en");
                    break;
                case 1:
                    LangUtil.getInstance().setLang("zh_cn");
                    break;
            }
            IndexForm index = new IndexForm();
            WSClientMIDlet.setDisplay(index);
        }
    }
    public List getList(){
        return list;
    }
}
